package logic

import (
	"context"
	"tieba/models/mysql"

	"tieba/tiebarpc/internal/svc"
	"tieba/tiebarpc/tiebarpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type TieBaAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewTieBaAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TieBaAddLogic {
	return &TieBaAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *TieBaAddLogic) TieBaAdd(in *tiebarpc.TieBaAddRequest) (*tiebarpc.TieBaAddResponse, error) {
	// todo: add your logic here and delete this line
	var tie = mysql.TieBa{
		TypeId: in.TypeId,
		Name:   in.Name,
	}
	mysql.DB.Debug().Create(&tie)
	return &tiebarpc.TieBaAddResponse{
		TieId: int64(tie.ID),
	}, nil
}
